package com.swt.testdemo.controller;

import com.swt.testdemo.config.ResponseMessage;
import com.swt.testdemo.form.SysLoginForm;
import com.swt.testdemo.service.StudentService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author BleethNie
 * @version 1.0
 * @date 2020/11/10 20:53
 **/
@RestController
@RequestMapping("/stu")
@Api(tags = "学生系统 -- 登录登出")
public class StuLoginController {

    @Autowired
    private StudentService studentService;

    @ApiOperation("01 学生登录")
    @PostMapping("/login")
    public ResponseEntity<ResponseMessage> login(SysLoginForm form){
        ResponseMessage response = studentService.login(form);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

    @ApiOperation("02 学生登出")
    @PostMapping("/logout")
    public ResponseEntity<ResponseMessage> logout(){
        ResponseMessage response = studentService.logout();
        return ResponseEntity.status(response.getStatus()).body(response);

    }

    @ApiOperation("03 获取验证码")
    @GetMapping(value = "/captcha",produces = "image/png")
    @ApiImplicitParam(name = "uuid", value = "随机码", required = true, paramType = "query", dataType = "string", defaultValue = "8e04634d-3420-47f8-a1af-392d77301bb9")
    public byte[] captcha(String uuid){
        return studentService.captcha(uuid);
    }


    @ApiOperation("04 登录破解版")
    @GetMapping(value = "/crack")
    @ApiImplicitParam(name ="uuid",value = "随机码",required = true,paramType = "query",dataType = "string",defaultValue = "8e04634d-3420-47f8-a1af-392d77301bb9")
    public ResponseEntity<ResponseMessage> crackUUid(String uuid){
        ResponseMessage response = studentService.crackUUid(uuid);
        return ResponseEntity.status(response.getStatus()).body(response);

    }

}
